Ext.define('Admin.view.PageList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.pagelist',
    
    requires: [ 
        'Admin.controller.ListController',
        'Admin.ux.GridFilters'
    ],
    scrollable:true,
    controller: 'list',
    plugins: ['gfilters'],
    bind: {
        store: '{objs}'
    },
    header:false,

    selModel: {
        selType: 'checkboxmodel',
        showHeaderCheckbox: false
    },
    tbar: ['->'/*,{
        text: '导入',
        handler: 'onImport',
        hidden:true        	
    }*/,{
        text: '录入',
        handler: 'onNew',
        hidden:true        	
    },{
        text: '克隆',
        handler: 'onClone',
        hidden:true
    },{
        text: '删除',
        handler: 'onRemove',
        hidden:true
    }
    ],
    bbar: [{
    	xtype: 'pagingtoolbar',
        bind: {
            store: '{objs}'
        },
        displayInfo: true,
        displayMsg: '当前: {0} - {1} 总数: {2}',
        emptyMsg: "无",
        items:['-']
    }],
   
	
	listeners: {
        itemdblclick: 'onDblClick',
    	afterlayout: function(grid,layout, eOpts) {
    		var bbar = grid.down('pagingtoolbar');
    		var st =bbar.getStore();
    		if(!st || st.isEmptyStore)
    			return;
            var maxRowsPerGrid = Math.floor(grid.getView().getHeight()/Admin.Cfg.ROW_HEIGHT)-1;
            maxRowsPerGrid=10
    		if(st.getPageSize()!=maxRowsPerGrid){
        		st.setPageSize(maxRowsPerGrid);
        		bbar.doRefresh();
    		}
    	}
    },
    
    initComponent: function(){
    	var me=this;
    	me.callParent();
        var perms = 'update;delete';
        if(Admin.Cfg.usrInfo)
            perms = Admin.Cfg.usrInfo.get('perms');
        //只读显示
        if(perms.indexOf('update')!=-1){
            /*if (me.down('button[text="导入"]')) {
                me.down('button[text="导入"]').setVisible(true);
            } */ 
            if (me.down('button[text="录入"]')) {
                me.down('button[text="录入"]').setVisible(true);
            }    		
            if (me.down('button[text="克隆"]')) {
                me.down('button[text="克隆"]').setVisible(true);
            }    		
        }
        if(perms.indexOf('delete')!=-1){ //管理员才显示删除按钮
            if (me.down('button[text="删除"]')) {
                me.down('button[text="删除"]').setVisible(true);
            }
        }  	
        me.on('edit', function(editor, e) {
            // commit the changes right after editing finished
            var rec = e.record;
            //rec.commit(true);
            rec.save({
                scope: this,
                callback: function(records,operation,success){
                    if(success)
                        Ext.toast({
                            title: '保存',
                            html: '['+rec.getId()+']保存完成',
                            align: 't',
                            bodyPadding: 10
                        });
                }
            });
            
        });
    		
    }
 });
